package cn.com.ytst.data.integration.core;

import cn.com.ytst.data.integration.core.container.AbstractContainer;
import cn.com.ytst.data.integration.core.container.JobContainer;
import cn.com.ytst.data.integration.exception.DataExchangeException;
import cn.com.ytst.data.integration.util.DictionaryEnu;

import com.google.common.collect.Maps;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.util.Map;

/**
 * @ClassName Engine
 * @Deacription 
 * @Author Administrator
 * @Date 2020/1/4 0004 13:55
 * @Version 1.0
 **/
public class DefaultEngine implements IEngine{

    private Logger logger = LoggerFactory.getLogger(this.getClass());


    private static Map<String ,AbstractContainer> jobcontainermap = Maps.newConcurrentMap();

    
    @Override
    public DictionaryEnu startengin(String file) {
        //加载作业文件
        File f = new File(file);
        //还需要一个作业容器，里面分别包含读作业和写作业，两个合起来才一个完整的作业
        AbstractContainer abstractContainer = new JobContainer();
        abstractContainer.setFile(f);
        try{
            abstractContainer.start();
            jobcontainermap.put(file,abstractContainer);
            return DictionaryEnu.SUCCESS;
        }catch (DataExchangeException e){
            logger.error("DataExchange 发生错误,请检查....{}",e);
        }
        return DictionaryEnu.FAIL;

    }

    @Override
    public DictionaryEnu stopengin(String file) {
        //还需要一个作业容器，里面分别包含读作业和写作业，两个合起来才一个完整的作业
        try{
            jobcontainermap.get(file).stop();
            return DictionaryEnu.SUCCESS;
        }catch (DataExchangeException e){
            logger.error("DataExchange 发生错误,请检查....{}",e);
        }
        return DictionaryEnu.FAIL;
    }
}
